import http.client
import operator


def get_cookie():
    conn = http.client.HTTPSConnection("aiqicha.baidu.com")
    # 发送HTTP GET请求
    conn.request("GET", "/")
    # 获取服务器响应
    response = conn.getresponse()
    # 从响应头中获取Set-Cookie头部信息
    set_cookie_header = response.getheader("Set-Cookie")
    # 如果存在Set-Cookie头部信息，则解析cookie
    if set_cookie_header:
        # 多个cookie可能在Set-Cookie头部中以分号分隔
        cookies = set_cookie_header.split(';')
        for cookie in cookies:
            if operator.contains(str(cookie), "BAIDUID"):
                return cookie
    # 关闭连接
    conn.close()


print(get_cookie())
